class Solution
{
public:
    vector<int> sortJumbled(vector<int> &mapping, vector<int> &nums)
    {
        auto mapInt = [&](int n)
        {
            if (n == 0)
            {
                return mapping[0];
            }
            int pos = 1;
            int result = 0;
            while (n)
            {
                result += pos * mapping[n % 10];
                n /= 10;
                pos *= 10;
            }
            return result;
        };
        stable_sort(nums.begin(), nums.end(), [&](int left, int right)
                    { return mapInt(left) < mapInt(right); });
        return nums;
    }
};